package opt.power.springdemo.login.controller;

import opt.power.springdemo.login.service.LoginService;
import opt.power.springdemo.user.mapper.model.User;
import opt.power.springdemo.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author xuliduo
 * @date 2017/11/16
 * @description class LoginController
 */
@Controller
@EnableAutoConfiguration
public class LoginController {
    LoginService loginService;
    UserService userService;

    @Autowired
    LoginController(LoginService loginService, UserService userService) {
        this.loginService = loginService;
        this.userService = userService;
    }

    @RequestMapping(path = "/login", method = RequestMethod.POST)
    @ResponseBody
    public User doLogin(@RequestBody User user) {
        if (loginService.checkLogin(user)) {
            user.setToken("12345");
        } else {
            user.setToken("-1");
        }
        return user;
    }


}
